using System;
using System.Configuration;
using System.Data;
using digit.Core;



namespace SMS.ServiceManager
{
    public class MatchManager
    {
        #region CONSTRUCTORS
        static MatchManager()
        {
            _data = new MatchData(Util.GetConnectionString("SMSSERVICE"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static MatchData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static bool Insert(long homeTeamID, long awayTeamID, string asiaHomeRate, string asiaAwayRate, string asiaRate, string upperRate, string lowerRate, string totalRate, string otherRate, string teamPicked, string finalScore, string timePlay, DateTime datePlay, string position, byte type, byte win, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[19];
                values[0] = homeTeamID;
                values[1] = awayTeamID;
                values[2] = Util.ReplaceNullTo(asiaHomeRate, DBNull.Value);
                values[3] = Util.ReplaceNullTo(asiaAwayRate, DBNull.Value);
                values[4] = Util.ReplaceNullTo(asiaRate, DBNull.Value);
                values[5] = Util.ReplaceNullTo(upperRate, DBNull.Value);
                values[6] = Util.ReplaceNullTo(lowerRate, DBNull.Value);
                values[7] = Util.ReplaceNullTo(totalRate, DBNull.Value);
                values[8] = Util.ReplaceNullTo(otherRate, DBNull.Value);
                values[9] = Util.ReplaceNullTo(teamPicked, DBNull.Value);
                values[10] = Util.ReplaceNullTo(finalScore, DBNull.Value);
                values[11] = Util.ReplaceNullTo(timePlay, DBNull.Value);
                values[12] = Util.ReplaceNullTo(datePlay, DBNull.Value);
                values[13] = Util.ReplaceNullTo(position, DBNull.Value);
                values[14] = Util.ReplaceNullTo(type, DBNull.Value);
                values[15] = Util.ReplaceNullTo(win, DBNull.Value);
                values[16] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[17] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[18] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Insert(MatchInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[19];
                values[0] = info.HomeTeamID;
                values[1] = info.AwayTeamID;
                values[2] = Util.ReplaceNullTo(info.AsiaHomeRate, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.AsiaAwayRate, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.AsiaRate, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.UpperRate, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.LowerRate, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.TotalRate, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.OtherRate, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.TeamPicked, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.FinalScore, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.TimePlay, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.DatePlay, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Position, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Type, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Win, DBNull.Value);
                values[16] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[17] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[18] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(long matchID, long homeTeamID, long awayTeamID, string asiaHomeRate, string asiaAwayRate, string asiaRate, string upperRate, string lowerRate, string totalRate, string otherRate, string teamPicked, string finalScore, string timePlay, DateTime datePlay, string position, byte type, byte win, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[20];
                values[0] = matchID;
                values[1] = homeTeamID;
                values[2] = awayTeamID;
                values[3] = Util.ReplaceNullTo(asiaHomeRate, DBNull.Value);
                values[4] = Util.ReplaceNullTo(asiaAwayRate, DBNull.Value);
                values[5] = Util.ReplaceNullTo(asiaRate, DBNull.Value);
                values[6] = Util.ReplaceNullTo(upperRate, DBNull.Value);
                values[7] = Util.ReplaceNullTo(lowerRate, DBNull.Value);
                values[8] = Util.ReplaceNullTo(totalRate, DBNull.Value);
                values[9] = Util.ReplaceNullTo(otherRate, DBNull.Value);
                values[10] = Util.ReplaceNullTo(teamPicked, DBNull.Value);
                values[11] = Util.ReplaceNullTo(finalScore, DBNull.Value);
                values[12] = Util.ReplaceNullTo(timePlay, DBNull.Value);
                values[13] = Util.ReplaceNullTo(datePlay, DBNull.Value);
                values[14] = Util.ReplaceNullTo(position, DBNull.Value);
                values[15] = Util.ReplaceNullTo(type, DBNull.Value);
                values[16] = Util.ReplaceNullTo(win, DBNull.Value);
                values[17] = Util.ReplaceNullTo(createdBy, DBNull.Value);
                values[18] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[19] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(MatchInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[20];
                values[0] = info.MatchID;
                values[1] = info.HomeTeamID;
                values[2] = info.AwayTeamID;
                values[3] = Util.ReplaceNullTo(info.AsiaHomeRate, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.AsiaAwayRate, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.AsiaRate, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.UpperRate, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.LowerRate, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.TotalRate, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.OtherRate, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.TeamPicked, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.FinalScore, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.TimePlay, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.DatePlay, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Position, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Type, DBNull.Value);
                values[16] = Util.ReplaceNullTo(info.Win, DBNull.Value);
                values[17] = Util.ReplaceNullTo(info.CreatedBy, DBNull.Value);
                values[18] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[19] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(long matchID)
        {
            _error = "";
            try
            {
                object[] values = { matchID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(MatchInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.MatchID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static MatchInfo Select(long matchID)
        {
            _error = "";
            try
            {
                object[] values = { matchID };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;


                MatchInfo info = new MatchInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAllToShow()
        {
            _error = "";
            try
            {
                return _data.SelectAllToShow();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectReportToShow()
        {
            _error = "";
            try
            {
                return _data.SelectReportToShow();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectTopReport()
        {
            _error = "";
            try
            {
                return _data.SelectTopReport();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        #endregion

    }
}